package edu.cmu.cs211.bacon.cable;

/**
 * 
 * A simple Java class to store the data associated with an edge for the
 * BaconCableCompany.  This class represents a weighted edge with
 * the cost to lay down wire between two locations. 
 * 
 */
public class CableWire {
    private String firstLocation;
    private String secondLocation;
    private double cost;
    
    /**
     * Constructs a CableWire.
     * 
     * @param s1
     *      The name of one endpoint of the edge.
     *      
     * @param s2
     *      The name of the other endpoint of the edge.
     *      
     * @param c
     *      The cost of laying down this CableWire.
     *      
     * @throws NullPointerException
     *      If either location is null.
     */
    public CableWire(String s1, String s2, double c) {
        if (s1 == null || s2 == null)
            throw new NullPointerException("Location name was null.");
        this.firstLocation = s1;
        this.secondLocation = s2;
        this.cost = c;
    }

    /**
     * 
     * @return The name of the first location-endpoint of the edge.
     */
    public String getFirstLocation() {
        return firstLocation;
    }

    /**
     * 
     * @return The name of the second location-endpoint of the edge.
     */
    public String getSecondLocation() {
        return secondLocation;
    }

    /**
     * 
     * @return The cost of laying down this CableWire.
     */
    public double getCost() {
        return cost;
    }
    
    public String toString() {
        return "(" + firstLocation + ", " + secondLocation + ", " + cost + ")";
    }
    
    public int hashCode() {
        return toString().hashCode();
    }
    
    public boolean equals(Object o) {
        if (!(o instanceof CableWire))
            return false;
        
        CableWire e = (CableWire) o;
        return (e.cost == cost && 
                e.firstLocation.equals(firstLocation) && 
                e.secondLocation.equals(secondLocation));
    }
}
